from sqlalchemy import Column, Integer, String

from app import login_manager
from app.model.base import Base
from flask_login import UserMixin

class User(Base, UserMixin):

    email = Column(String (50), unique=True, nullable=False)
    id = Column(Integer, primary_key=True)
    nickname = Column(String(24), nullable=False)
    # 字符串的内容就是最终数据库里表的名字
    password = Column(String(24), nullable=False)

    def check_password(self, raw):
        return self.password == raw


@login_manager.user_loader
def get_user(uid):
    return User.query.get(int(uid))